import { createRouter } from 'vue-router'
import routerConfig from './router'
import Cookie from "../utils/cache";
import {globalStore} from '../store/globalStore.js'
import tab_pages from '../utils/constant/tab_pages.js'

const router = createRouter(routerConfig)

router.beforeEach((to, from, next) => {
  if (!to.meta.skip_auth && !Cookie.get("authorization")) {
    next({
      path: "/login",
      query: {
        redirect: to.fullPath
      }
    });
    return
  }
  next();
});
router.afterEach((toRoute,fromRoute) => {
  console.log(toRoute,tab_pages.includes(toRoute.path),"toRoute")
  globalStore.changeTabBarState(tab_pages.includes(toRoute.path))
  window.scrollTo(0, 0);
});

export default router;
